package gwt.immunology.server.converter;

import static gwt.immunology.shared.GenericDtoKeys.ID;
import static gwt.immunology.shared.GenericDtoKeys.NAME;
import gwt.immunology.shared.GenericDto;
import gwt.immunology.shared.ResultSetDto;

import java.util.ArrayList;
import java.util.List;

import models.Syndrome;

public class SyndromeDtoConverter {

    public static GenericDto convertSyndromeToGenericDto(Syndrome syndrome) {
	GenericDto result = new GenericDto();
	if (syndrome != null) {
	    result.put(ID, syndrome.syndromeId);
	    result.put(NAME, syndrome.name);
	}
	return result;
    }

    public static Syndrome convertGenericDtoToSyndrome(GenericDto syndromeDto) {
	Syndrome result = null;
	if (syndromeDto != null && !syndromeDto.isEmpty()) {
	    result = new Syndrome();
	    result.syndromeId = syndromeDto.getLong(ID);
	    result.name = syndromeDto.getString(NAME);
	}
	return result;
    }

    public static ResultSetDto convertSyndromesToResultSetDto(List<Syndrome> syndromes) {
	ResultSetDto result = new ResultSetDto();
	if (syndromes != null && !syndromes.isEmpty()) {
	    for (Syndrome syndrome : syndromes) {
		GenericDto syndromeDto = convertSyndromeToGenericDto(syndrome);
		result.add(syndromeDto);
	    }
	}
	return result;
    }

    public static List<Syndrome> convertResultSetDtoToSyndromes(ResultSetDto syndromeResultSet) {
	List<Syndrome> result = new ArrayList<Syndrome>();
	if (syndromeResultSet != null && !syndromeResultSet.isEmpty()) {
	    for (GenericDto syndromeDto : syndromeResultSet) {
		Syndrome syndrome = convertGenericDtoToSyndrome(syndromeDto);
		result.add(syndrome);
	    }
	}
	return result;
    }

}
